import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:flutter_localizations/flutter_localizations.dart';
import 'package:time_manager/app/store/global_data.dart';
import 'package:time_manager/global/binds.dart';
import 'app/routes/app_pages.dart';

void main() async {
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({Key? key}) : super(key: key);

  void hideKeyboard(BuildContext context) {
    FocusScopeNode currentFocus = FocusScope.of(context);
    if (!currentFocus.hasPrimaryFocus && currentFocus.focusedChild != null) {
      FocusManager.instance.primaryFocus?.unfocus();
    }
  }

  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    Get.put(GlobalData());
    return GetBuilder<GlobalData>(
      builder: (store) {
        return GetMaterialApp(
          title: '日程新建',
          initialRoute: AppPages.INITIAL,
          initialBinding: GlobalBinding(),
          getPages: AppPages.routes,
          // ignore: prefer_const_literals_to_create_immutables
          supportedLocales: [
            const Locale('zh'),
            const Locale('en'),
          ],
          builder: (context, child) => GestureDetector(
            onTap: () {
              hideKeyboard(context);
            },
            child: child,
          ),

          // ignore: prefer_const_literals_to_create_immutables
          localizationsDelegates: const [
            GlobalMaterialLocalizations.delegate,
            GlobalWidgetsLocalizations.delegate,
            GlobalCupertinoLocalizations.delegate,
          ],
        );
      },
    );
  }
}
